<!--注意id属性每个页面id必须独立，lay-title为当前页面的标题属性-->
<div class="layui-fluid layui-anim febs-anim" id="hr-outsideTeacherForSeelct" lay-title="选择讲师">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <!--注意lay-filter属性，该属性为form表单唯一属性-->
                    <form class="layui-form layui-table-form" lay-filter="outsideTeacher-table-form" id="selectForm">
                        <!--fieldset为区分搜索区域-->
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <!-- 查询信息 -->
                            <div class="layui-col-md11">
                                <!-- layui-form-item为自适应长度样式 -->
                                <div class="layui-form-item">
                                    <!-- layui-inline样式为单行多控件 -->
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">讲师姓名</label>
                                        <div class="layui-input-inline">
                                            <!-- 注意name属性于定义的实体类属性一致，placeholder设置提示用语-->
                                            <!-- maxlength设置最大长度-->
                                            <input type="text" name="realName" autocomplete="off" class="layui-input"
                                                   placeholder="关键字" minlength="0" maxlength="20">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">讲师类型</label>
                                        <div class="layui-input-inline">
                                            <select name="lecturerType" id="selectLecturer" lay-filter="selectLecturer">
                                                <option value=""></option>
                                                <option value="0" selected="true">外部讲师</option>
                                                <option value="1" lay-event="inside">内部讲师</option>
                                            </select>
                                        </div>
                                    </div>

                                </div>


                            </div>

                            <!-- 查询重置按钮 -->
                            <!-- 注意id属性 用于绑定JS事件-->
                            <div class="layui-col-md1 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain
                                            table-action" id="hr-outsideTeacherForSelect-query-btn">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain
                                            table-action" id="hr-outsideTeacherForSelect-reset-btn">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>

                    <!-- 表格 -->
                    <!-- 注意lay-filter和id属性，两者需保持一致 用于绑定JS事件-->
                    <table lay-filter="hr-outsideTeacher-outsideTeacherForSelect-table"
                           lay-data="{id: 'hr-outsideTeacher-outsideTeacherForSelect-table'}">
                    </table>

                    <div align="center" style="text-align:center" >
                        <input type="button" class="layui-btn" lay-submit="" lay-filter="select-btnCheckResults-submit"
                               id="btnCheckResults" value="确定">
                        <input type="button" class="layui-btn" lay-submit="" lay-filter="select-btnCheckCancel-submit"
                               id="btnCheckCancel" value="取消">

                    </div>
                </div>
            </div>

        </div>

    </div>

</div>

<script type="text/html" id="outsideTeacherForSelect-sex">
    {{#
    let sex = {
    4000: {title: '男'},
    0: {title: '男'},
    4001: {title: '女'},
    1: {title: '女'},
    4003: {title: '未知'},
    null: {title: '保密'},
    2: {title: '保密'}
    }[d.sex];
    }}
    <span>{{ sex.title }}</span>
</script>


<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            // 定义页面视图
            $view = $('#hr-outsideTeacherForSeelct'),
            // 定义查询按钮
            $query = $view.find('#hr-outsideTeacherForSelect-query-btn'),
            // 定义重置按钮
            $reset = $view.find('#hr-outsideTeacherForSelect-reset-btn'),
            // 定义form表单
            $searchForm = $view.find('form'),
            // 定义表格排序
            sortObject = {field: 'address', type: null},
            tableIns;
        // 表单渲染
        form.render();

        // 调用列表初始化方法
        initTable();

        // 查询按钮点击事件
        $query.on('click', function () {
            // 获得页面检索条件
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            // 重新加载列表
            tableIns.reload({where: params, page: {curr: 1}});
            console.log(params);
        });

        // 在个位数的时间前加0
        function formatZero(n) {
            if (n >= 0 && n <= 9) {
                return "0" + n;
            } else {
                return n;
            }
        }

        // 重置按钮点击事件
        $reset.on('click', function () {
            // 清空表单信息
            $searchForm[0].reset();
            sortObject.type = 'null';
            // 重新加载表格数据
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        // 初始化数据表格
        function initTable() {
            tableIns = febs.table.init({
                // 当前视图的table
                elem: $view.find('table'),
                // 列表ID
                id: 'hr-outsideTeacher-outsideTeacherForSelect-table',
                // 访问路由
                url: ctx + 'outsideTeacher/selectList',
                // 配置列表顶部右侧显示列过滤项
                defaultToolbar: ['filter'],
                // 表格渲染完毕后的回调
                done: function (res, curr, count) {
                    // 调整表格在页面占比
                    $("table").css("width", "100%");
                },
                width: "100%",
                // field属性为返回实体类中相关属性名，title为表格列头显示内容，minWidth为表格列最小宽度，maxWidth为表格列最大宽度
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', minWidth: 100},
                    {field: 'realName', title: '真实姓名', minWidth: 100},
                    {title: '性别', templet: '#outsideTeacherForSelect-sex'},
                    {field: 'phone', title: '常用手机', minWidth: 200},
                    {field: 'wxid', title: '微信号', minWidth: 100},
                    {field: 'mail', title: '邮箱', minWidth: 200},
                    {field: 'lastModifyDate', title: '最后修改日期', minWidth: 200}
                ]]
            });
        }

        form.on('select(selectLecturer)', function (data) {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});

            if (data.value == 0) {
                console.log("外部员工界面");
                // 重新加载表格数据
                // 获得页面检索条件
                let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                // 重新加载列表
                tableIns.reload({where: params, page: {curr: 1}});
                console.log(params);

            } else {
                console.log("内部员工界面");
                // 重新加载表格数据
                // 获得页面检索条件
                let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                // 重新加载列表
                tableIns.reload({where: params, page: {curr: 1}});

            }

        });

        // 获得form表单中查询条件并格式化为JSON格式
        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }

        //按回车搜索
        $(".layui-input").keyup(function (e) {
            //当按下按键时
            //.which属性判断按下的是哪个键，回车键的键位序号为13
            if (e.which == 13) {
                $query.click();
            }
        });
        //确定
        $("#btnCheckResults").click(function () {
            let checkStatus = table.checkStatus("hr-outsideTeacher-outsideTeacherForSelect-table");
            let data = checkStatus.data;
            console.log(data);
            let lecturer_id = [];//存id
            if (data.length > 0) {
                for (let i = 0; i < data.length; i++) {
                    let check = data[i];
                    lecturer_id.push(check.id);

                }
                console.log(lecturer_id);

            } else {
                febs.alert.warn('至少选择一个讲师');
            }
        });

        //取消
        $("#btnCheckCancel").click(function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

    })
</script>